<?php
// +----------------------------------------------------------------------
// | OneThink [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: 麦当苗儿 <zuojiazi@vip.qq.com> <http://www.zjzit.cn>
// +----------------------------------------------------------------------

namespace Home\Controller;

/**
 * 文档模型控制器
 * 文档模型列表和详情
 */
class LeavewordController extends HomeController {

    /* 文档模型频道页 */
	public function index(){
		//$Leaveword   =   D('Leaveword');
		//$list = $Leaveword->lists();
		//$this->assign('list',$list);
		//dump(D('Leaveword')->listCount());
		
		$this->display();
	}
	public function index1(){
		//实例化主表模型对象
		$model = M('leaveword lw');
		//实现主表关联分类表并查询相关数据总条数
		$total = $model->join('onethink_leavewordtype lt ON lw.type=lt.id')->count();
		//获取每页条数
		if( isset($REQUEST['r']) ){
            $listRows = (int)$REQUEST['r'];
        }else{
            $listRows = C('LIST_ROWS') > 0 ? C('LIST_ROWS') : 10;
        }
		//实例化分页对象
        $page = new \COM\Page($total, $listRows, $REQUEST);
        if($total>$listRows){
        	//定制分页链接设置
            $page->setConfig('theme','%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END% %HEADER%');
        }
		//实现主表关联分类表并查询相关数据
		$list = $model->field('lw.id,lw.name,lw.mobile,lw.title,lw.ctime,lw.reply_userid,lw.reply_userid,lw.status,lw.type,lt.name tname')
				->order('lw.id desc')
				->join('onethink_leavewordtype lt ON lw.type=lt.id')->limit($page->firstRow.','.$page->listRows)->select();
		//组装分页链接
		$this->assign('list', $list);
		$this->assign('page', $page->show()); //页码
		$this->display();
	}
	/* 我要留言页*/
	public function question(){
		$this->display();
	}
	/* 文档模型详情页 */
	public function detail($id = 0, $page = 1){
		/* 标识正确性检测 */
		if(!($id && is_numeric($id))){
			$this->error('文档ID错误！');
		}

		/* 页码检测 */
		$page = intval($page);
		$page = empty($page) ? 1 : $page;
		
		/* 获取详细信息 */
		$Leaveword = D('Leaveword');
		$info = $Leaveword->detail($id);
		if(!$info){
			$this->error($Leaveword->getError());
		}
		$this->assign('info', $info);
		$this->assign('page', $page); //页码
		$this->display();
	}
}